package com.ruoyi.project.data.damage.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.data.damage.domain.FractureDamageInfo;
import com.ruoyi.project.data.damage.service.IFractureDamageInfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 断裂损伤信息Controller
 * 
 * @author ruoyi
 * @date 2024-04-27
 */
@Controller
@RequestMapping("/data/damage")
public class FractureDamageInfoController extends BaseController
{
    private String prefix = "data/damage";

    @Autowired
    private IFractureDamageInfoService fractureDamageInfoService;

    @RequiresPermissions("data:damage:view")
    @GetMapping()
    public String damage()
    {
        return prefix + "/damage";
    }

    /**
     * 查询断裂损伤信息列表
     */
    @RequiresPermissions("data:damage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FractureDamageInfo fractureDamageInfo)
    {
        startPage();
        List<FractureDamageInfo> list = fractureDamageInfoService.selectFractureDamageInfoList(fractureDamageInfo);
        return getDataTable(list);
    }

    /**
     * 导出断裂损伤信息列表
     */
    @RequiresPermissions("data:damage:export")
    @Log(title = "断裂损伤信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FractureDamageInfo fractureDamageInfo)
    {
        List<FractureDamageInfo> list = fractureDamageInfoService.selectFractureDamageInfoList(fractureDamageInfo);
        ExcelUtil<FractureDamageInfo> util = new ExcelUtil<FractureDamageInfo>(FractureDamageInfo.class);
        return util.exportExcel(list, "断裂损伤信息数据");
    }

    /**
     * 新增断裂损伤信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存断裂损伤信息
     */
    @RequiresPermissions("data:damage:add")
    @Log(title = "断裂损伤信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FractureDamageInfo fractureDamageInfo)
    {
        return toAjax(fractureDamageInfoService.insertFractureDamageInfo(fractureDamageInfo));
    }

    /**
     * 修改断裂损伤信息
     */
    @RequiresPermissions("data:damage:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        FractureDamageInfo fractureDamageInfo = fractureDamageInfoService.selectFractureDamageInfoById(id);
        mmap.put("fractureDamageInfo", fractureDamageInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存断裂损伤信息
     */
    @RequiresPermissions("data:damage:edit")
    @Log(title = "断裂损伤信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FractureDamageInfo fractureDamageInfo)
    {
        return toAjax(fractureDamageInfoService.updateFractureDamageInfo(fractureDamageInfo));
    }

    /**
     * 删除断裂损伤信息
     */
    @RequiresPermissions("data:damage:remove")
    @Log(title = "断裂损伤信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fractureDamageInfoService.deleteFractureDamageInfoByIds(ids));
    }
}
